package cz.muni.fi.pa165.web;

import java.security.Principal;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Controller class for working with main page "index"
 *
 * @author Marek Tuharsky
 */
@Controller
public class MainPageController {

    @RequestMapping(value = "/")
    public String initial(ModelMap modelMap) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName(); //get logged in username
        modelMap.addAttribute("username", name);
        return "index";
    }

    @RequestMapping(value = "index")
    public String home(ModelMap modelMap) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName(); //get logged in username
        modelMap.addAttribute("username", name);
        return "index";
    }

    @RequestMapping(value = "/login")
    public String login() {
        return "login";
    }
}
